package com.study.security.service;

import com.study.constant.CommonConstant;
import com.study.pojo.MyUserDetails;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.List;


public class MemoryUserDetailsService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws
            UsernameNotFoundException {
        // 1.根据username查询数据库，判断用户名是否存在

        // 2.将数据库当中查出来的username和pwd封装到user对象当中返回 第三个参数表示权限
        List<GrantedAuthority> grantedAuthorities = AuthorityUtils.commaSeparatedStringToAuthorityList(CommonConstant.Role.ROLE_PREFIX+CommonConstant.Role.OAUTH_ROLE);
        return new MyUserDetails(1L,username, "$2a$10$guxh7Ajozpck4/kchBICAuO.C8f7zp/ZU06f05PAILenfBNL18uFe", grantedAuthorities);
    }
}
